﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AMS.SubCipherSolver
{
    public static class ExtensionMethods
    {
        public static void Raise(this EventHandler me, object sender, EventArgs args)
        {
            if (me != null)
                me(sender, args);
        }

        public static void Raise<T>(this EventHandler<T> me, object sender, T args) where T : EventArgs
        {
            if (me != null)
                me(sender, args);
        }

        public static string ReplaceAllWhiteSpace(this string me)
        {
            char[] a = me.Replace("\r\n", " ").ToArray();
            for (int i = 0; i < a.Length; i++)
            {
                if (char.IsWhiteSpace(a[i]))
                    a[i] = ' ';
            }
            me = new string(a);
            while (me.Contains("  "))
                me = me.Replace("  ", " ");
            return me;
        }
    }
}
